package com.fz.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by ZCY on 2018-01-26.
 */
public class MybatisUtil {
    public SqlSessionFactory sf;
    public SqlSession session;
    public MybatisUtil() {
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(is);
       session = sf.openSession();
    }
    public SqlSession getSession(){
        return session;
    }
}
